import JSEncrypt from 'jsencrypt'

import Encrypt from 'encryptlong'

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCVlKc39tiRrmEtpm1WEQNxMw5vgZhCYXI7B8zXr5gCki+tpo29HpSkJkB3f+0TAO1MKBxnu593T7hMuIUcj6hT+GEXq8ub2KBNoE8J/tZ6WW8PX44zQpuQMSMBG/2Hg9hroyT4IYe8dCfREV73tYVRrdMMwG+H+/aXiDBgKd9SiQIDAQAB'
const privateKey = ''
export default {
  /* JSEncrypt加密 */
  rsaPublicData(data) {
    var jsencrypt = new JSEncrypt()
    jsencrypt.setPublicKey(publicKey)
    // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
    var result = jsencrypt.encrypt(data)
    var signdata = window.btoa(result)
    return signdata
  },
  /* JSEncrypt解密 */
  rsaPrivateData(data) {
    var jsencrypt = new JSEncrypt()
    jsencrypt.setPrivateKey(privateKey)
    // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
    var result = jsencrypt.encrypt(data)
    return result
  },
  /* 加密 */
  encrypt(data) {
    const PUBLIC_KEY = publicKey
    var encryptor = new Encrypt()
    encryptor.setPublicKey(PUBLIC_KEY)
    // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
    const result = encryptor.encryptLong(data)
    const signdata = window.btoa(result)
    return signdata
  },
  /* 解密 - PRIVATE_KEY - 验证 */
  decrypt(data) {
    const PRIVATE_KEY = privateKey
    var encryptor = new Encrypt()
    encryptor.setPrivateKey(PRIVATE_KEY)
    // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
    var result = encryptor.decryptLong(data)
    return result
  }
}
